// pages/myCenter/msgcenter/msgcenter.js
let app = getApp();
let httptool=require("../../../utils/zry.httptool.js");
Page({
  data:{
    params:{},
    atype:0,
    checkList:[],//
    msgprop:'',//消息提示 
    noData: false,
    clickarea:false,
    clickarea2:false,
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    let that=this;
    that.getcheckPeoplist();
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  getcheckPeoplist:function(){
    let that = this;
    let customerId = app.getStorage('customerId');
    that.setData({ customerId: customerId });
    httptool.ajaxPost("api/MyCircle/GetMyCircleApply", { UserId: customerId }, function (res) {
      if (res.suc) {
        let data = app.notNull(res.data, []);
        for(let i=0;i < data.length;i++){
          let date = new Date(data[i].CreateTime); 
          let m = date.getMonth() + 1;  
             m = m < 10 ? ('0' + m) : m;
            let d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            let h = date.getHours();
            h = h < 10 ? ('0' + h) : h;
            let minute = date.getMinutes();
            minute = minute < 10 ? ('0' + minute) : minute;
            data[i].CreateTime = m + '-' + d + ' ' + h + ':' + minute;  
        }
        that.setData({ checkList: data, noData: data.length==0 });
      } else {
        app.showNotify(that, res.msg);
      }
    });
  },
  agreeApply:function(e){
      let that=this;
      let customerId = app.getStorage('customerId');
      let atype = e.currentTarget.dataset.atype;
      let index = e.currentTarget.dataset.index;
      // if(atype==1){
      //     that.setData({clickarea:true});
      // }else{
      //     that.setData({clickarea:false});
      // }
      // if(atype==2){
      //     that.setData({clickarea2:true});
      // }else{
      //     that.setData({clickarea2:false});
      // }
      let id=e.currentTarget.dataset.id;
      let status=e.currentTarget.dataset.status;//1 同意  2：拒绝
      let Remark='';
      that.data.params.UserId=customerId;
      that.data.params.Status=status;
      that.data.params.ID=id;
      that.data.params.Remark=Remark;
      that.setData({atype:atype,params:that.data.params});
      that.checkApply(index);
  },
  checkApply: function (index){
    let that = this;
    httptool.ajaxPost("api/MyCircle/ChkApplyCircle", that.data.params, function (res) {
      if (res.suc) {
        let title="";
        if(that.data.atype==1){
          title='已同意';           
        }else if(that.data.atype==2){
          title = '已忽略';        
        }
        app.showNotify(that, title, function(){
          that.getcheckPeoplist();
        });  
      } else {
        app.showNotify(that, res.msg);
      }
    });
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})